<?php namespace App\Providers;

use App\Services\AliyunLogService;
use Illuminate\Support\ServiceProvider;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

class AliyunLogProvider extends ServiceProvider
{
    protected $logService;

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->logService = new AliyunLogService();

        $this->app->singleton('AliyunLog', function($app) {
            return $this->logService;
        });

        $this->app->configureMonologUsing(function ($logger) {
            /**
             * @var $logger Logger
             */
            $logger->pushHandler($this->logService);
            $logger->pushHandler((new StreamHandler(storage_path('logs/lumen.log'), Logger::DEBUG))
                ->setFormatter(new LineFormatter(null, null, true, true)));

            return $logger;
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array-
     */
    public function provides()
    {
        return ['AliyunLog'];
    }
}
